package com.work.util;

import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;

public class ComponentFactory {
	
	public static final String BOLD_START = "<b>";
	public static final String BOLD_STOP = "</b>";
	public static final String ITALIC_START = "<i>";
	public static final String ITALIC_STOP = "</i>";
	
	public static Label createLabel(String caption, String width, String height, ContentMode contentMode) {
		Label newLabel = new Label(caption);
		newLabel.setContentMode(contentMode);
		
		if (width != null) {
			newLabel.setWidth(width);	
		}
		if (height != null) {
			newLabel.setHeight(height);	
		}
		
		return newLabel;
	}
	
	public static Label createLabel(String caption, String width, String height, ContentMode contentMode, boolean bold, boolean italic) {
		StringBuilder sb = new StringBuilder(caption);
		
		if (bold) {
			sb.insert(0, BOLD_START);
			sb.append(BOLD_STOP);
		}
		
		if (italic) {
			sb.insert(0, ITALIC_START);
			sb.append(ITALIC_STOP);
		}
		
		return createLabel(sb.toString(), width, height, contentMode);
	}
}
